# 封装一些基础的方法操作
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

import Page


class Base():
    # 初始化driver
    def __init__(self, driver):
        self.driver = driver

    # 查找元素
    def base_find_element(self, loc, tmme=30, poll=0.5):
        return WebDriverWait(self.driver, timeout=tmme, poll_frequency=poll).until(lambda x: x.find_element(*loc))

    # 点击元素
    def base_click_element(self, loc):
        self.base_find_element(loc).click()

    # 输入
    def base_input_text(self, loc, text):
        self.base_find_element(loc).send_keys(text)

    # 滑动拖拽
    def base_drag_and_drop(self):
        self.driver.drag_and_drop()

    # 截图
    def base_get_screenshot_as_file(self, filenamePATH):
        self.driver.get_screenshot_as_file(filenamePATH)

    # 获取toast
    def base_get_toast(self, loc):
        return self.base_find_element(loc).text

    # 获取元素文本方法
    def base_get_element_text(self, loc):
        return self.base_find_element(loc).text

    # 获取toast文本方法
    def base_xpath(self, text1):
        loc = By.XPATH, "//*[contains(@text,'"+text1+"')]"
        return self.base_find_element(loc)

    # 要把错误的用户名和错误的密码断言合二为一
    def base_get_toast_01(self,text):
        return self.base_xpath(text).text
